package com.cencat.order.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 订单创建VO
 * @author cencat
 * @description 固定商家场景多租户SaaS企业综合管理系统订单创建VO
 * @since 2024-01-01
 */
@Data
@Accessors(chain = true)
@Schema(name = "OrderCreateVO", description = "订单创建VO")
public class OrderCreateVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "商家ID")
    @NotNull(message = "商家ID不能为空")
    private Long merchantId;

    @Schema(description = "用户ID")
    @NotNull(message = "用户ID不能为空")
    private Long userId;

    @Schema(description = "用户姓名")
    @NotBlank(message = "用户姓名不能为空")
    @Size(max = 100, message = "用户姓名长度不能超过100个字符")
    private String userName;

    @Schema(description = "用户手机号")
    @NotBlank(message = "用户手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "用户手机号格式不正确")
    private String userPhone;

    @Schema(description = "用户邮箱")
    @Email(message = "用户邮箱格式不正确")
    @Size(max = 100, message = "用户邮箱长度不能超过100个字符")
    private String userEmail;

    @Schema(description = "收货人姓名")
    @NotBlank(message = "收货人姓名不能为空")
    @Size(max = 100, message = "收货人姓名长度不能超过100个字符")
    private String receiverName;

    @Schema(description = "收货人手机号")
    @NotBlank(message = "收货人手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "收货人手机号格式不正确")
    private String receiverPhone;

    @Schema(description = "收货人邮箱")
    @Email(message = "收货人邮箱格式不正确")
    @Size(max = 100, message = "收货人邮箱长度不能超过100个字符")
    private String receiverEmail;

    @Schema(description = "收货地址省份")
    @NotBlank(message = "收货地址省份不能为空")
    @Size(max = 50, message = "收货地址省份长度不能超过50个字符")
    private String receiverProvince;

    @Schema(description = "收货地址城市")
    @NotBlank(message = "收货地址城市不能为空")
    @Size(max = 50, message = "收货地址城市长度不能超过50个字符")
    private String receiverCity;

    @Schema(description = "收货地址区县")
    @NotBlank(message = "收货地址区县不能为空")
    @Size(max = 50, message = "收货地址区县长度不能超过50个字符")
    private String receiverDistrict;

    @Schema(description = "收货详细地址")
    @NotBlank(message = "收货详细地址不能为空")
    @Size(max = 200, message = "收货详细地址长度不能超过200个字符")
    private String receiverAddress;

    @Schema(description = "收货地址邮编")
    @Pattern(regexp = "^\\d{6}$", message = "收货地址邮编格式不正确")
    private String receiverPostcode;

    @Schema(description = "配送方式：EXPRESS-快递配送，SELF_PICKUP-自提")
    @NotBlank(message = "配送方式不能为空")
    @Pattern(regexp = "^(EXPRESS|SELF_PICKUP)$", message = "配送方式不正确")
    private String shippingMethod;

    @Schema(description = "配送费用")
    @DecimalMin(value = "0.00", message = "配送费用不能为负数")
    @Digits(integer = 10, fraction = 2, message = "配送费用格式不正确")
    private BigDecimal shippingFee;

    @Schema(description = "支付方式：ALIPAY-支付宝，WECHAT-微信支付，BANK_CARD-银行卡，CASH-现金")
    @Pattern(regexp = "^(ALIPAY|WECHAT|BANK_CARD|CASH)$", message = "支付方式不正确")
    private String paymentMethod;

    @Schema(description = "优惠券ID")
    private Long couponId;

    @Schema(description = "优惠券编码")
    @Size(max = 64, message = "优惠券编码长度不能超过64个字符")
    private String couponCode;

    @Schema(description = "优惠金额")
    @DecimalMin(value = "0.00", message = "优惠金额不能为负数")
    @Digits(integer = 10, fraction = 2, message = "优惠金额格式不正确")
    private BigDecimal discountAmount;

    @Schema(description = "订单备注")
    @Size(max = 500, message = "订单备注长度不能超过500个字符")
    private String remark;

    @Schema(description = "订单来源：WEB-网页，APP-手机应用，MINI_PROGRAM-小程序，H5-手机网页")
    @Pattern(regexp = "^(WEB|APP|MINI_PROGRAM|H5)$", message = "订单来源不正确")
    private String orderSource;

    @Schema(description = "订单类型：NORMAL-普通订单，PRESALE-预售订单，GROUP_BUY-团购订单")
    @Pattern(regexp = "^(NORMAL|PRESALE|GROUP_BUY)$", message = "订单类型不正确")
    private String orderType;

    @Schema(description = "是否需要发票：0-不需要，1-需要")
    @Min(value = 0, message = "是否需要发票值不正确")
    @Max(value = 1, message = "是否需要发票值不正确")
    private Integer needInvoice;

    @Schema(description = "发票类型：PERSONAL-个人，COMPANY-企业")
    @Pattern(regexp = "^(PERSONAL|COMPANY)$", message = "发票类型不正确")
    private String invoiceType;

    @Schema(description = "发票抬头")
    @Size(max = 200, message = "发票抬头长度不能超过200个字符")
    private String invoiceTitle;

    @Schema(description = "发票税号")
    @Size(max = 50, message = "发票税号长度不能超过50个字符")
    private String invoiceTaxNo;

    @Schema(description = "发票内容")
    @Size(max = 500, message = "发票内容长度不能超过500个字符")
    private String invoiceContent;

    @Schema(description = "订单明细列表")
    @NotEmpty(message = "订单明细不能为空")
    @Valid
    private List<OrderItemCreateVO> orderItems;

    /**
     * 订单明细创建VO
     */
    @Data
    @Accessors(chain = true)
    @Schema(name = "OrderItemCreateVO", description = "订单明细创建VO")
    public static class OrderItemCreateVO implements Serializable {

        private static final long serialVersionUID = 1L;

        @Schema(description = "产品ID")
        @NotNull(message = "产品ID不能为空")
        private Long productId;

        @Schema(description = "产品编码")
        @NotBlank(message = "产品编码不能为空")
        @Size(max = 64, message = "产品编码长度不能超过64个字符")
        private String productCode;

        @Schema(description = "产品名称")
        @NotBlank(message = "产品名称不能为空")
        @Size(max = 200, message = "产品名称长度不能超过200个字符")
        private String productName;

        @Schema(description = "产品规格")
        @Size(max = 500, message = "产品规格长度不能超过500个字符")
        private String productSpec;

        @Schema(description = "产品图片URL")
        @Size(max = 500, message = "产品图片URL长度不能超过500个字符")
        private String productImage;

        @Schema(description = "产品单价")
        @NotNull(message = "产品单价不能为空")
        @DecimalMin(value = "0.01", message = "产品单价必须大于0")
        @Digits(integer = 10, fraction = 2, message = "产品单价格式不正确")
        private BigDecimal unitPrice;

        @Schema(description = "购买数量")
        @NotNull(message = "购买数量不能为空")
        @Min(value = 1, message = "购买数量必须大于0")
        private Integer quantity;

        @Schema(description = "产品分类ID")
        private Long categoryId;

        @Schema(description = "产品分类名称")
        @Size(max = 100, message = "产品分类名称长度不能超过100个字符")
        private String categoryName;

        @Schema(description = "产品品牌ID")
        private Long brandId;

        @Schema(description = "产品品牌名称")
        @Size(max = 100, message = "产品品牌名称长度不能超过100个字符")
        private String brandName;

        @Schema(description = "产品重量(克)")
        @DecimalMin(value = "0.00", message = "产品重量不能为负数")
        @Digits(integer = 10, fraction = 2, message = "产品重量格式不正确")
        private BigDecimal weight;

        @Schema(description = "产品体积(立方厘米)")
        @DecimalMin(value = "0.00", message = "产品体积不能为负数")
        @Digits(integer = 10, fraction = 2, message = "产品体积格式不正确")
        private BigDecimal volume;

        @Schema(description = "明细备注")
        @Size(max = 500, message = "明细备注长度不能超过500个字符")
        private String remark;
    }
}